1 /* 2 3 Boost Software License - Version 1.0 - August 17th, 2003 4 5 Permission is hereby granted, free of charge, to any person or organization 6 obtaining a copy of the software and accompanying documentation covered by 7 this license (the "Software") to use, reproduce, display, distribute, 8 execute, and transmit the Software, and to prepare derivative works of the 9 Software, and to permit third-parties to whom the Software is furnished to 10 do so, all subject to the following: 11 12 The copyright notices in the Software and this entire statement, including 13 the above license grant, this restriction and the following disclaimer, 14 must be included in all copies of the Software, in whole or in part, and 15 all derivative works of the Software, unless such copies or derivative 16 works are solely in the form of machine-executable object code generated by 17 a source language processor. 18 19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 22 SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 23 FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 24 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 DEALINGS IN THE SOFTWARE. 26 27 */ 28 29 module derelict.purple.cipher; 30 31 import derelict.glib.gtypes; 32 import derelict.glib.glibconfig; 33 import derelict.glib.glist; 34 35 extern (C): 36 37 alias _PurpleCipher PurpleCipher; 38 alias _PurpleCipherOps PurpleCipherOps; 39 alias _PurpleCipherContext PurpleCipherContext; 40 alias _PurpleCipherBatchMode PurpleCipherBatchMode; 41 alias _PurpleCipherCaps PurpleCipherCaps; 42 43 enum _PurpleCipherBatchMode 44 { 45 PURPLE_CIPHER_BATCH_MODE_ECB = 0, 46 PURPLE_CIPHER_BATCH_MODE_CBC = 1 47 } 48 49 enum _PurpleCipherCaps 50 { 51 PURPLE_CIPHER_CAPS_SET_OPT = 2, 52 PURPLE_CIPHER_CAPS_GET_OPT = 4, 53 PURPLE_CIPHER_CAPS_INIT = 8, 54 PURPLE_CIPHER_CAPS_RESET = 16, 55 PURPLE_CIPHER_CAPS_UNINIT = 32, 56 PURPLE_CIPHER_CAPS_SET_IV = 64, 57 PURPLE_CIPHER_CAPS_APPEND = 128, 58 PURPLE_CIPHER_CAPS_DIGEST = 256, 59 PURPLE_CIPHER_CAPS_ENCRYPT = 512, 60 PURPLE_CIPHER_CAPS_DECRYPT = 1024, 61 PURPLE_CIPHER_CAPS_SET_SALT = 2048, 62 PURPLE_CIPHER_CAPS_GET_SALT_SIZE = 4096, 63 PURPLE_CIPHER_CAPS_SET_KEY = 8192, 64 PURPLE_CIPHER_CAPS_GET_KEY_SIZE = 16384, 65 PURPLE_CIPHER_CAPS_SET_BATCH_MODE = 32768, 66 PURPLE_CIPHER_CAPS_GET_BATCH_MODE = 65536, 67 PURPLE_CIPHER_CAPS_GET_BLOCK_SIZE = 131072, 68 PURPLE_CIPHER_CAPS_SET_KEY_WITH_LEN = 262144, 69 PURPLE_CIPHER_CAPS_UNKNOWN = 524288 70 } 71 72 struct _PurpleCipherOps 73 { 74 void function (PurpleCipherContext*, const(gchar)*, void*) set_option; 75 void* function (PurpleCipherContext*, const(gchar)*) get_option; 76 void function (PurpleCipherContext*, void*) init; 77 void function (PurpleCipherContext*, void*) reset; 78 void function (PurpleCipherContext*) uninit; 79 void function (PurpleCipherContext*, guchar*, size_t) set_iv; 80 void function (PurpleCipherContext*, const(guchar)*, size_t) append; 81 gboolean function (PurpleCipherContext*, size_t, guchar*, size_t*) digest; 82 int function (PurpleCipherContext*, const(guchar)*, size_t, guchar*, size_t*) encrypt; 83 int function (PurpleCipherContext*, const(guchar)*, size_t, guchar*, size_t*) decrypt; 84 void function (PurpleCipherContext*, guchar*) set_salt; 85 size_t function (PurpleCipherContext*) get_salt_size; 86 void function (PurpleCipherContext*, const(guchar)*) set_key; 87 size_t function (PurpleCipherContext*) get_key_size; 88 void function (PurpleCipherContext*, PurpleCipherBatchMode) set_batch_mode; 89 PurpleCipherBatchMode function (PurpleCipherContext*) get_batch_mode; 90 size_t function (PurpleCipherContext*) get_block_size; 91 void function (PurpleCipherContext*, const(guchar)*, size_t) set_key_with_len; 92 } 93 94 struct _PurpleCipherContext; 95 96 97 struct _PurpleCipher; 98 99 version(Derelict_Link_Static) 100 { 101 extern( C ) nothrow 102 { 103 const(gchar)* purple_cipher_get_name(PurpleCipher* cipher); 104 guint purple_cipher_get_capabilities(PurpleCipher* cipher); 105 gboolean purple_cipher_digest_region(const(gchar)* name, const(guchar)* data, size_t data_len, size_t in_len, guchar* digest, size_t* out_len); 106 PurpleCipher* purple_ciphers_find_cipher(const(gchar)* name); 107 PurpleCipher* purple_ciphers_register_cipher(const(gchar)* name, PurpleCipherOps* ops); 108 gboolean purple_ciphers_unregister_cipher(PurpleCipher* cipher); 109 GList* purple_ciphers_get_ciphers(); 110 gpointer purple_ciphers_get_handle(); 111 void purple_ciphers_init(); 112 void purple_ciphers_uninit(); 113 void purple_cipher_context_set_option(PurpleCipherContext* context, const(gchar)* name, gpointer value); 114 gpointer purple_cipher_context_get_option(PurpleCipherContext* context, const(gchar)* name); 115 PurpleCipherContext* purple_cipher_context_new(PurpleCipher* cipher, void* extra); 116 PurpleCipherContext* purple_cipher_context_new_by_name(const(gchar)* name, void* extra); 117 void purple_cipher_context_reset(PurpleCipherContext* context, gpointer extra); 118 void purple_cipher_context_destroy(PurpleCipherContext* context); 119 void purple_cipher_context_set_iv(PurpleCipherContext* context, guchar* iv, size_t len); 120 void purple_cipher_context_append(PurpleCipherContext* context, const(guchar)* data, size_t len); 121 gboolean purple_cipher_context_digest(PurpleCipherContext* context, size_t in_len, guchar* digest, size_t* out_len); 122 gboolean purple_cipher_context_digest_to_str(PurpleCipherContext* context, size_t in_len, gchar* digest_s, size_t* out_len); 123 gint purple_cipher_context_encrypt(PurpleCipherContext* context, const(guchar)* data, size_t len, guchar* output, size_t* outlen); 124 gint purple_cipher_context_decrypt(PurpleCipherContext* context, const(guchar)* data, size_t len, guchar* output, size_t* outlen); 125 void purple_cipher_context_set_salt(PurpleCipherContext* context, guchar* salt); 126 size_t purple_cipher_context_get_salt_size(PurpleCipherContext* context); 127 void purple_cipher_context_set_key(PurpleCipherContext* context, const(guchar)* key); 128 size_t purple_cipher_context_get_key_size(PurpleCipherContext* context); 129 void purple_cipher_context_set_batch_mode(PurpleCipherContext* context, PurpleCipherBatchMode mode); 130 PurpleCipherBatchMode purple_cipher_context_get_batch_mode(PurpleCipherContext* context); 131 size_t purple_cipher_context_get_block_size(PurpleCipherContext* context); 132 void purple_cipher_context_set_key_with_len(PurpleCipherContext* context, const(guchar)* key, size_t len); 133 void purple_cipher_context_set_data(PurpleCipherContext* context, gpointer data); 134 gpointer purple_cipher_context_get_data(PurpleCipherContext* context); 135 gchar* purple_cipher_http_digest_calculate_session_key(const(gchar)* algorithm, const(gchar)* username, const(gchar)* realm, const(gchar)* password, const(gchar)* nonce, const(gchar)* client_nonce); 136 gchar* purple_cipher_http_digest_calculate_response(const(gchar)* algorithm, const(gchar)* method, const(gchar)* digest_uri, const(gchar)* qop, const(gchar)* entity, const(gchar)* nonce, const(gchar)* nonce_count, const(gchar)* client_nonce, const(gchar)* session_key); 137 } 138 } 139 else 140 { 141 extern( C ) nothrow 142 { 143 alias da_purple_cipher_get_name = const(gchar)* function(PurpleCipher* cipher); 144 alias da_purple_cipher_get_capabilities = guint function(PurpleCipher* cipher); 145 alias da_purple_cipher_digest_region = gboolean function(const(gchar)* name, const(guchar)* data, size_t data_len, size_t in_len, guchar* digest, size_t* out_len); 146 alias da_purple_ciphers_find_cipher = PurpleCipher* function(const(gchar)* name); 147 alias da_purple_ciphers_register_cipher = PurpleCipher* function(const(gchar)* name, PurpleCipherOps* ops); 148 alias da_purple_ciphers_unregister_cipher = gboolean function(PurpleCipher* cipher); 149 alias da_purple_ciphers_get_ciphers = GList* function(); 150 alias da_purple_ciphers_get_handle = gpointer function(); 151 alias da_purple_ciphers_init = void function(); 152 alias da_purple_ciphers_uninit = void function(); 153 alias da_purple_cipher_context_set_option = void function(PurpleCipherContext* context, const(gchar)* name, gpointer value); 154 alias da_purple_cipher_context_get_option = gpointer function(PurpleCipherContext* context, const(gchar)* name); 155 alias da_purple_cipher_context_new = PurpleCipherContext* function(PurpleCipher* cipher, void* extra); 156 alias da_purple_cipher_context_new_by_name = PurpleCipherContext* function(const(gchar)* name, void* extra); 157 alias da_purple_cipher_context_reset = void function(PurpleCipherContext* context, gpointer extra); 158 alias da_purple_cipher_context_destroy = void function(PurpleCipherContext* context); 159 alias da_purple_cipher_context_set_iv = void function(PurpleCipherContext* context, guchar* iv, size_t len); 160 alias da_purple_cipher_context_append = void function(PurpleCipherContext* context, const(guchar)* data, size_t len); 161 alias da_purple_cipher_context_digest = gboolean function(PurpleCipherContext* context, size_t in_len, guchar* digest, size_t* out_len); 162 alias da_purple_cipher_context_digest_to_str = gboolean function(PurpleCipherContext* context, size_t in_len, gchar* digest_s, size_t* out_len); 163 alias da_purple_cipher_context_encrypt = gint function(PurpleCipherContext* context, const(guchar)* data, size_t len, guchar* output, size_t* outlen); 164 alias da_purple_cipher_context_decrypt = gint function(PurpleCipherContext* context, const(guchar)* data, size_t len, guchar* output, size_t* outlen); 165 alias da_purple_cipher_context_set_salt = void function(PurpleCipherContext* context, guchar* salt); 166 alias da_purple_cipher_context_get_salt_size = size_t function(PurpleCipherContext* context); 167 alias da_purple_cipher_context_set_key = void function(PurpleCipherContext* context, const(guchar)* key); 168 alias da_purple_cipher_context_get_key_size = size_t function(PurpleCipherContext* context); 169 alias da_purple_cipher_context_set_batch_mode = void function(PurpleCipherContext* context, PurpleCipherBatchMode mode); 170 alias da_purple_cipher_context_get_batch_mode = PurpleCipherBatchMode function(PurpleCipherContext* context); 171 alias da_purple_cipher_context_get_block_size = size_t function(PurpleCipherContext* context); 172 alias da_purple_cipher_context_set_key_with_len = void function(PurpleCipherContext* context, const(guchar)* key, size_t len); 173 alias da_purple_cipher_context_set_data = void function(PurpleCipherContext* context, gpointer data); 174 alias da_purple_cipher_context_get_data = gpointer function(PurpleCipherContext* context); 175 alias da_purple_cipher_http_digest_calculate_session_key = gchar* function(const(gchar)* algorithm, const(gchar)* username, const(gchar)* realm, const(gchar)* password, const(gchar)* nonce, const(gchar)* client_nonce); 176 alias da_purple_cipher_http_digest_calculate_response = gchar* function(const(gchar)* algorithm, const(gchar)* method, const(gchar)* digest_uri, const(gchar)* qop, const(gchar)* entity, const(gchar)* nonce, const(gchar)* nonce_count, const(gchar)* client_nonce, const(gchar)* session_key); 177 } 178 179 __gshared 180 { 181 da_purple_cipher_get_name purple_cipher_get_name; 182 da_purple_cipher_get_capabilities purple_cipher_get_capabilities; 183 da_purple_cipher_digest_region purple_cipher_digest_region; 184 da_purple_ciphers_find_cipher purple_ciphers_find_cipher; 185 da_purple_ciphers_register_cipher purple_ciphers_register_cipher; 186 da_purple_ciphers_unregister_cipher purple_ciphers_unregister_cipher; 187 da_purple_ciphers_get_ciphers purple_ciphers_get_ciphers; 188 da_purple_ciphers_get_handle purple_ciphers_get_handle; 189 da_purple_ciphers_init purple_ciphers_init; 190 da_purple_ciphers_uninit purple_ciphers_uninit; 191 da_purple_cipher_context_set_option purple_cipher_context_set_option; 192 da_purple_cipher_context_get_option purple_cipher_context_get_option; 193 da_purple_cipher_context_new purple_cipher_context_new; 194 da_purple_cipher_context_new_by_name purple_cipher_context_new_by_name; 195 da_purple_cipher_context_reset purple_cipher_context_reset; 196 da_purple_cipher_context_destroy purple_cipher_context_destroy; 197 da_purple_cipher_context_set_iv purple_cipher_context_set_iv; 198 da_purple_cipher_context_append purple_cipher_context_append; 199 da_purple_cipher_context_digest purple_cipher_context_digest; 200 da_purple_cipher_context_digest_to_str purple_cipher_context_digest_to_str; 201 da_purple_cipher_context_encrypt purple_cipher_context_encrypt; 202 da_purple_cipher_context_decrypt purple_cipher_context_decrypt; 203 da_purple_cipher_context_set_salt purple_cipher_context_set_salt; 204 da_purple_cipher_context_get_salt_size purple_cipher_context_get_salt_size; 205 da_purple_cipher_context_set_key purple_cipher_context_set_key; 206 da_purple_cipher_context_get_key_size purple_cipher_context_get_key_size; 207 da_purple_cipher_context_set_batch_mode purple_cipher_context_set_batch_mode; 208 da_purple_cipher_context_get_batch_mode purple_cipher_context_get_batch_mode; 209 da_purple_cipher_context_get_block_size purple_cipher_context_get_block_size; 210 da_purple_cipher_context_set_key_with_len purple_cipher_context_set_key_with_len; 211 da_purple_cipher_context_set_data purple_cipher_context_set_data; 212 da_purple_cipher_context_get_data purple_cipher_context_get_data; 213 da_purple_cipher_http_digest_calculate_session_key purple_cipher_http_digest_calculate_session_key; 214 da_purple_cipher_http_digest_calculate_response purple_cipher_http_digest_calculate_response; 215 } 216 }